import java.util.*;

public class FoxAndDoraemon {

	int[] workCost;
	int splitCost;
	
	int[][] rec;
	
	private int rec(int nfoxes, int jobN) {
		if (rec[nfoxes][jobN] == 0) {			
			if (nfoxes >= workCost.length - jobN) rec[nfoxes][jobN] = workCost[jobN];
			else if (nfoxes == 1) rec[nfoxes][jobN] = rec(2, jobN) + splitCost;
			else {
				rec[nfoxes][jobN] = Integer.MAX_VALUE;
				for (int i=1; i<=nfoxes; i++) {
					if (workCost.length - (jobN+(nfoxes-i)) +1 >= i*2) {
						if (i <nfoxes) {
							rec[nfoxes][jobN] = Math.min(Math.max(workCost[jobN],  rec(i*2, jobN+(nfoxes-i))+splitCost), rec[nfoxes][jobN]);
						} else {
							rec[nfoxes][jobN] = Math.min(rec(i*2, jobN)+splitCost, rec[nfoxes][jobN]);
						}
					}
				}
			}
		}
		
				
		return rec[nfoxes][jobN];
	}
	
	public int minTime(int[] workCost, int splitCost) {
		Arrays.sort(workCost);
		this.workCost = new int[workCost.length];
		for (int i=0; i<workCost.length; i++) this.workCost[i] = workCost[workCost.length-1-i];
				
		this.splitCost = splitCost;
		
		rec = new int[101][101];
		for (int i=0; i<101; i++) {
			for (int j=0; j<101; j++) {
				rec[i][j] = 0;
			}
		}
		
		return rec(1, 0);
	}

}
